#include <list>
#include <sstream>
#include "Pizzeria/Tests/PizzaOrderParser_tests.hpp"
#include "Pizzeria/PizzaOrderParser.hpp"

namespace pizzeria {

PizzaOrderParser_tests::PizzaOrderParser_tests()
    : mTestRunner("Orders' parser tests")
{
  mTestRunner.AddTestCase(
      UTESTS_MAKE_CASE_DATA(PizzaOrderParser_tests::InvalidArguments));
  mTestRunner.AddTestCase(
      UTESTS_MAKE_CASE_DATA(PizzaOrderParser_tests::ListGeneration));
  mTestRunner.Run(true);
}

PizzaOrderParser_tests::~PizzaOrderParser_tests() {

}

UTESTS_START_TEST(PizzaOrderParser_tests::InvalidArguments)
  {
    PizzaOrderParser parser0("reGina	s X4	 ;;  aMERiCainE Xl	x22");
    TestIfExceptionRaised("");
    TestIfExceptionRaised("      			");
    TestIfExceptionRaised("a		a a");
    TestIfExceptionRaised("fantasia M x2 x");
    TestIfExceptionRaised("regina XL x3; ;");
    TestIfExceptionRaised("regina sl x-1");
    TestIfExceptionRaised("regina s x4294967295");
    TestIfExceptionRaised("fg s x4");
    TestIfExceptionRaised("margarita z x4");
  }
  UTESTS_END_TEST

UTESTS_START_TEST(PizzaOrderParser_tests::ListGeneration)
  {
    std::list<Pizza> list = PizzaOrderParser::GetPizzaListFromOrder(
	"fantasia M x4 ; americaine XL x26");
    UTESTS_FAIL_UNLESS(list.size() == 4 + 26, "list size is wrong");
  }
  UTESTS_END_TEST

void PizzaOrderParser_tests::TestIfExceptionRaised(const std::string &order) {
  bool exceptionRaised = false;
  try {
    PizzaOrderParser parser(order);
  }
  catch (std::invalid_argument &e) {
    exceptionRaised = true;
  }
  if (!exceptionRaised)
    UTESTS_FAIL(
	std::string("`") + order + std::string("' didn't raised an exception"));
}

} /* namespace pizzeria */
